home *** CD-ROM | disk | FTP | other *** search
- #
- # Demonstration Tools
- #
- #
- # TODO:
- # make code for creating different bars reusable
-
- ###############################################################################
- # Thumb Attachements
- ###############################################################################
-
- CreateThumb = FUNCTION(vect):
- return = sphereSrf(0.025) * trans(vect);
-
- CreateAnimThumb = FUNCTION(curve): thumb: pt: cent: mov_xyz: visible:
- pt = ceval(curve, 0):
- cent = vector(coord(pt, 1) ,coord(pt, 2), 0):
- thumb = CreateThumb(cent):
- mov_xyz = curve*trans(-cent):
- visible = ctlpt(E1, 0) + ctlpt(E1, 10):
- attrib(thumb, "animation", list(mov_xyz, visible)):
- return = thumb;
-
- AttachThumbToCurve = FUNCTION(curve):
- return = list(curve, CreateAnimThumb(curve));
-
- AttachNodesToCtlpoly = FUNCTION(plgn, colors): obj: i:
- return = list(plgn):
- for (i=1, 1, sizeof(plgn),
- obj = CreateThumb(coerce(coord(plgn, i-1), VECTOR_TYPE)):
- color(obj, nth(colors, i)):
- snoc(obj, return)
- );
-
- ###############################################################################
- # Parametric Domain Knot Bar
- ###############################################################################
-
- KnotVectorPlacement = FUNCTION(knotVector): xlen: delta: i: klist: x: y:
- # Returns:
- # list of horizontal placements for the knot vector values in IRIT
- # bspline demo 'domain area'.
-
- x = 0.6:
- y = -0.7:
- xlen = sizeof(knotVector):
- klist = nil():
- delta = nth(knotVector, xlen) - nth(knotVector,1):
- for (i=1, 1, xlen,
- snoc((nth(knotVector,i)-nth(knotVector,1)) / delta, klist)
- ):
- return = list(vector(-x, y, 0)):
- for (i=2, 1, xlen,
- delta = 2*x*(nth(klist, i) - 0.5): # x = -x0 + dx*(t-t0)/dt
- if (nth(klist, i) == nth(klist, i-1),
- snoc(vector(delta, coord(nth(return, i-1), 1)-0.04, 0), return),
- snoc(vector(delta, y, 0), return)
- )
- );
-
- KnotVectorBar = FUNCTION(order, knotVector):
- # Returns:
- # list of object representing knot vector domain bar, placed horizontally
- # and aligned in IRIT Bspline Demo 'domain area', with knots positions
- # marked by cones, placed under domain bar. Multiple notes are taken care
- # by stacking one under another. Colors are used to distinguish bspline
- # curve domain.
-
- xlen: places: xl: xr: y: l1: l2: step: i: tri: bar: thumb: mov_xyz:
-
- xlen = sizeof(knotVector):
- places = KnotVectorPlacement(knotVector):
- xl = coord(nth(places, 1), 0):
- xr = coord(nth(places, xlen), 0):
- y = coord(nth(places, 1), 1):
-
- # Create bar line
-
- bar = ctlpt(E2, xl, y) + ctlpt(E2, xr, y):
- color(bar, white):
- return = list(bar):
-
- # Create large tick marks
-
- l1 = ctlpt(E2, xl, y - 0.025) + ctlpt(E2, xl, y + 0.025):
- color(l1, white):
- snoc(l1, return):
- snoc(l1 * tx(xr-xl), return):
-
- # Create small tick marks
-
- step = (xr - xl) / (xlen - 1):
- l2 = ctlpt(E2, xl, y - 0.015) + ctlpt(E2, xl, y + 0.015):
- color(l2, white):
- for (i=0, 1, xlen-1, snoc(l2 * tx(i*step), return)):
-
- # Create knot vector representation
-
- tri = coneSrf(0.04, 0.02) * (rotx(-90) * ty(-0.07)):
- color(tri, white): # grey color
- for (i=1, 1, order-1, snoc(tri*trans(nth(places, i)), return)):
- color(tri, yellow):
- for (i=order, 1, xlen-order+1, snoc(tri*trans(nth(places, i)), return)):
- color(tri, white):
- for (i=xlen-order+2, 1, xlen, snoc(tri*trans(nth(places, i)), return));
-
-
- KnotVectorBarWithThumb = FUNCTION(order, knotVector, t):
- # Requires:
- # t is insode knotVector domain.
- # Returns:
- # list of objects from knot vector bar and thumb object at 't'.
-
- places: xlen: xl: xr: tl: tr: thumb:
- places = KnotVectorPlacement(knotVector):
- xlen = sizeof(knotVector):
- xl = coord(nth(places, 1), 0):
- xr = coord(nth(places, xlen), 0):
- tl = nth(knotVector, 1):
- tr = nth(knotVector, xlen):
- xl = xl + (t - tl) * (xr - xl) / (tr - tl):
- return = KnotVectorBar(order, knotVector):
- thumb = CreateThumb(vector(xl, coord(nth(places, 1), 1), 0)):
- color(thumb, white):
- snoc(thumb, return);
-
-
- KnotVectorBarAnimThumb = FUNCTION(knotVector, ind1, ind2): places: l: r: crv:
- # Returns:
- # thumb with animation curve from 'knotVector[ind1]' to 'knotVector[ind2]'
-
- places = KnotVectorPlacement(knotVector):
- l = nth(places, ind1):
- r = nth(places, ind2):
- crv = ctlpt(E2, coord(l, 0), coord(l, 1)) + ctlpt(E2, coord(r, 0), coord(r, 1)):
- return = CreateAnimThumb(crv);
-
- ###############################################################################
- # Ratio bar widget
- ###############################################################################
-
- RatioBar = FUNCTION(pt0, pt1, ratio): v: l: r:
- v = pt0*(1.0-ratio) + pt1*ratio:
- l = coerce(pt0, E2) + coerce(v, E2):
- attrib(l, "dwidth", 5):
- color(l, 7): # gray
- r = coerce(v, E2) + coerce(pt1, E2):
- attrib(r, "dwidth", 5):
- color(r, yellow):
- return = list(l, r);
-